package com.tony.model;

import com.tony.utils.DateUtil;
import net.sf.json.JSONObject;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Record {

    private long id;
    private int itemId;
    private String itemName;
    private String itemNumbers;
    private String dateTimes;
    private int itemType;


    private String dbPath;

    public Record (String dbPath){
        this.dbPath=dbPath;
    }


    public boolean insertData(JSONObject json,int type){
        try{
            Class.forName("org.sqlite.JDBC");
            Connection conn = DriverManager.getConnection("jdbc:sqlite:"+ this.dbPath);
            Statement stmt = conn.createStatement();
            String sql="INSERT INTO task_record_info ('itemId','itemName','itemNumbers','dateTimes','itemType')" +
                    " VALUES ("+json.getInt("id")+",'"+json.getString("player_name")+"',"+json.getInt("number")+",'"+ DateUtil.getCurrentDateTime()+"',"+type+")";
            stmt.executeUpdate(sql);
            stmt.close();
            conn.close();
            return true;
        }catch (Exception e){
            //e.printStackTrace();
            System.err.println("数据插入操作异常");
        }
        return false;
    }







    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getItemId() {
        return itemId;
    }

    public void setItemId(int itemId) {
        this.itemId = itemId;
    }

    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public String getItemNumbers() {
        return itemNumbers;
    }

    public void setItemNumbers(String itemNumbers) {
        this.itemNumbers = itemNumbers;
    }

    public String getDateTimes() {
        return dateTimes;
    }

    public void setDateTimes(String dateTimes) {
        this.dateTimes = dateTimes;
    }

    public int getItemType() {
        return itemType;
    }

    public void setItemType(int itemType) {
        this.itemType = itemType;
    }
}
